﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using yncTech.Common;
using yncTech.BusinessObjects;
using System.Collections;
using System.Data;

public partial class Admin_FinMov_FinMov004 : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
         
        }

    }



    protected void PageChanged(object sender, DataGridPageChangedEventArgs e)
    {
        FinShippingQuery q1 = new FinShippingQuery("q1");
        TSCodeTableQuery q2 = new TSCodeTableQuery("q2");
        TSCodeTableQuery q3 = new TSCodeTableQuery("q3");
        TSCodeTableQuery q4 = new TSCodeTableQuery("q4");
        BFThirdUnitQuery q5 = new BFThirdUnitQuery("q5");
        BFThirdUnitQuery q6 = new BFThirdUnitQuery("q6");

       
        q1.InnerJoin(q2).On(q1.ShippingStatus == q2.Code);
        q1.LeftJoin(q3).On(q1.TransferType == q3.Code);
        q1.LeftJoin(q4).On(q1.TransportType == q4.Code);
        q1.LeftJoin(q5).On(q1.FromDestination == q5.ThirdUnitID);
        q1.LeftJoin(q6).On(q1.ToDestination == q6.ThirdUnitID);
        q1.Select(q1.ShipID, q1.CreatedBy, q1.CreatedDttm, q5.Name.As("FromDestination"), q6.Name.As("ToDestination"), q6.ThirdType,
            q1.IsChecked, q1.Check1, q1.Check2, q1.Sender, q1.ShippingDate, q1.ReceivedBy, q1.ShippingStatus.As("ShippingStatusCode"), q1.ReceivedDttm, q1.Comments, q1.AttachmentName, q2.Value1.As("ShippingStatus"), q4.Value1.As("TransferType"), q3.Value1.As("TransportType"))
            .Where(q1.ShippingStatus == ConstantValue.ShippingStatusCode.Delivery);
        q1.OrderBy(q1.CreatedDttm.Descending);

        DataTable dt = q1.LoadDataTable();
        Business.SetShippingNo(dt);

        pageGrid.DataSource = dt;
        pageGrid.CurrentPage = e.NewPageIndex;
        pageGrid.DataBind();
    }

    protected override void OnUnload(EventArgs e)
    {
        base.OnUnload(e);
        Session.Remove("sd");
        Session.Remove("ed");
        Session.Remove("ZYstatus");
    }

    protected string GetActionUrl(string status, object rowView)
    {
        string retUrl = "";
        switch (status)
        {
            case ConstantValue.ShippingStatusCode.Delivery:

                retUrl = GetLinkExt("转移", "aTansfer", "A", "FinMov004a.aspx", rowView, 580, 380, false, VShippingInfoMetadata.ColumnNames.ShipID);
               
                break;
            //case ConstantValue.ShippingStatusCode.NeedReply://等待回复
            //    retUrl = GetLink("添加凭证盒", "A", "FinMov001b.aspx", rowView, 980, 580, false, VShippingInfoMetadata.ColumnNames.ShipID);
            //    break;
        }



        //if (status.Equals(ConstantValue.ShippingStatusCode.Pending))
        //{

        //    if (boxCount > 0)
        //    {
        //        retUrl += "   " + GetLink("确认转移", "A", "FinMov001d.aspx", rowView, 980, 580, false, VShippingInfoMetadata.ColumnNames.ShipID);
        //    }


        //}

        return retUrl;
    }



    protected string getBoxCount(object Id, object status)
    {
        string result = "0";
        FinShippingBoxesCollection finShippingBoxesCollection = new FinShippingBoxesCollection();
        finShippingBoxesCollection.Query.Where(finShippingBoxesCollection.Query.ShipID == int.Parse(Id.ToString()));
        finShippingBoxesCollection.Query.Load();

        result = finShippingBoxesCollection.Count.ToString() + "[<a class='aDocument' title='打包查看' href=\"FinMov001h.aspx?type=V&returl=FinMov004&ShipID=" + Id.ToString() + "\"></a>]";



        return result;
    }

    protected string getThirdName(object name, object type)
    {
        if (type.ToString() == "JGLX003")
            return name.ToString();
        else
            return "否";
    }
}